import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
//远程服务器地址
let remoteIp = "https://health-system-imgs.oss-cn-hangzhou.aliyuncs.com/imgs/";
export default new Vuex.Store({
  state: {
    ipAddr: remoteIp + "avatar",
    coverPre: remoteIp + "cover/",
    contentImg: remoteIp + "contentImg/",
    identityImg: remoteIp + "identityImg/",
    serverIp: "localhost:9090/api", //服务器地址接口
    // serverIp: "47.113.226.111:9090/api", //服务器地址接口
    userId: "",
    userName: "",
    avatar: "",
    isCountingDown: false, //验证码正在倒计时
    countDown: 0, //倒计时数字
  },
  getters: {
    getIpAddr: (state) => state.ipAddr,
    getCoverPre: (state) => state.coverPre, // 添加获取封面图片地址的getter
    getContentImg: (state) => state.contentImg, // 添加获取内容图片地址的getter
    getIdentityImg: (state) => state.identityImg, // 添加获取身份图片地址的getter
    getServerIp: (state) => state.serverIp,
    getUserId: (state) => state.userId,
    getUserName: (state) => state.userName,
    getAvatar: (state) => state.avatar,
  },
  mutations: {
    setIpAddr(state, ipAddr) {
      state.ipAddr = ipAddr;
    },
    setCoverPre(state, coverPre) {
      // 添加设置封面图片地址的mutation
      state.coverPre = coverPre;
    },
    setContentImg(state, contentImg) {
      // 添加设置内容图片地址的mutation
      state.contentImg = contentImg;
    },
    setIdentityImg(state, identityImg) {
      // 添加设置内容图片地址的mutation
      state.identityImg = identityImg;
    },
    setUserId(state, userId) {
      state.userId = userId;
    },
    setUserName(state, userName) {
      state.userName = userName;
    },
    setAvatar(state, avatar) {
      state.avatar = avatar;
    },
    setIsCountingDown(state, value) {
      state.isCountingDown = value;
    },
    setCountDown(state, value) {
      state.countDown = value;
    },
    setServerIp(state, serverIp) {
      state.serverIp = serverIp;
    },
  },
  actions: {
    updateIpAddr({ commit }, ipAddr) {
      commit("setIpAddr", ipAddr);
    },
    updateCoverPre({ commit }, coverPre) {
      // 添加更新封面图片地址的action
      commit("setCoverPre", coverPre);
    },
    updateContentImg({ commit }, contentImg) {
      // 添加更新封面图片地址的action
      commit("setContentImg", contentImg);
    },
    updateIdentityImg({ commit }, identityImg) {
      // 添加更新封面图片地址的action
      commit("setIdentityImg", identityImg);
    },
    updateUserId({ commit }, userId) {
      commit("setUserId", userId);
    },
    updateUserName({ commit }, userName) {
      commit("setUserName", userName);
    },
    updateAvatar({ commit }, avatar) {
      commit("setAvatar", avatar);
    },
    startCountdown({ commit }) {
      commit("setIsCountingDown", true);
    },
    stopCountdown({ commit }) {
      commit("setIsCountingDown", false);
    },
    updateCountDown({ commit }, value) {
      commit("setCountDown", value);
    },
    updateServerIp({ commit }, serverIp) {
      commit("setServerIp", serverIp);
    },
  },
});
